package org.fuys.etp.core.metrics.impl.trend.type.impl;

import org.fuys.etp.core.metrics.impl.trend.type.StageJudgeTypeProcessor;
import org.fuys.etp.core.model.vo.TpConfigVO;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @projectName: fuys-etp
 * @package: org.fuys.etp.core.metrics.fixed.impl
 * @className: BlockQueueRatioHandler
 * @author: WangJing
 * @description: 阻塞队列比值处理
 * @date: 2025/2/8 18:36
 * @version: 1.0
 */
@Component("blockQueueRatioHandle")
public class BlockQueueRatioHandler implements StageJudgeTypeProcessor {
    @Override
    public Integer judge(boolean expansion, String compareType, ThreadPoolExecutor poolExecutor, TpConfigVO configVO) {
        final int size = poolExecutor.getQueue().size();
        Integer target = expansion?configVO.getFixedConfig().getExpansionNum():configVO.getFixedConfig().getScaleNum();
        final double ratio = (size*1.0 / configVO.getBaseConfig().getWorkQueueSize()) * 100.0;
        return compare(compareType,Double.parseDouble(target.toString()),
                ratio,expansion);
    }
}
